package com.glq1218.background.controller;

import com.glq1218.common.dto.QueryUserListDTO;
import com.glq1218.common.dto.UserDTO;
import com.glq1218.common.entity.User;
import com.glq1218.common.model.PageRes;
import com.glq1218.common.model.Result;
import com.glq1218.common.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制器
 *
 * @author glq1218
 */
@Tag(name = "用户管理")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    @Operation(summary = "查询用户列表接口")
    @GetMapping("/")
    public Result<PageRes<UserDTO>> queryUserList(@Validated QueryUserListDTO queryUserListDTO) {
        return Result.ok(userService.queryUserList(queryUserListDTO));
    }

    @Operation(summary = "根据id查询用户信息")
    @GetMapping("/{id}")
    public Result<UserDTO> queryUserList(@PathVariable("id") Long id) {
        User user = userService.getById(id);
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(user, userDTO);
        return Result.ok(userDTO);
    }

    @Operation(summary = "添加用户接口")
    @PostMapping("/")
    public Result<?> addUser(@RequestBody UserDTO userDTO) {
        return Result.ok(userService.addUser(userDTO));
    }

    @Operation(summary = "更新用户接口")
    @PutMapping("/updateUser")
    public Result<?> updateUser(@RequestBody UserDTO userDTO) {
        // return Result.ok(userService.updateUser(userDTO));
        return Result.fail("暂未开发");
    }
}
